package com.example.oasystem.service.impl;

import com.example.oasystem.dao.address.AoaDirectorDao;
import com.example.oasystem.entity.address.AoaDirector;
import com.example.oasystem.entity.daymanage.EmpDTO;
import com.example.oasystem.entity.user.AoaUser;
import com.example.oasystem.utils.DateUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
public class AddressServiceImpl {
    @Autowired
    AoaDirectorDao directorDao;
    public PageInfo<AoaUser> getIndoorUserLimit(int pageNum, int pageSize, String text, String baseKey) {
        PageHelper.startPage(pageNum, pageSize);
        List<AoaUser> indoorUser = directorDao.getIndoorUser(text,baseKey);
        PageInfo<AoaUser> pageInfo = new PageInfo<AoaUser>(indoorUser);
        return pageInfo;
    }
    public List<String> getCate(Long userId) {
        List<String> cate = directorDao.getCate(userId);
        cate.removeIf(t -> t == null || "".equals(t));
        return cate;
    }
    /*public PageInfo<EmpDTO> getAllEmpsLimit(int pageNum, int pageSize, String text){
        PageHelper.startPage(pageNum,pageSize);
        System.out.println("进来了"+text);
        List<EmpDTO> allEmps = directorDao.getAllEmps(text);
        for (EmpDTO allEmp : allEmps) {
            System.out.println(allEmp);
        }
        PageInfo<EmpDTO> pageInfo = new PageInfo<>(allEmps);
        return pageInfo;
    }*/
    public PageInfo<AoaDirector> getOutUserLimit(int userId, String text, int pageNum, int pageSize, String outtype,String baseKey) {
        PageHelper.startPage(pageNum, pageSize);
        List<AoaDirector> outUser = directorDao.getOutUser(userId, text, outtype,baseKey);
        PageInfo<AoaDirector> pageInfo = new PageInfo<>(outUser);
        return pageInfo;
    }
   /* public PageInfo<EmpDTO> getemp( String text, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<EmpDTO> outUser = directorDao.getAllEmps(text);
        PageInfo<EmpDTO> pageInfo = new PageInfo<>(outUser);
        return pageInfo;
    }*/
    public PageInfo<AoaDirector> getMeShareMessLimit(Long userId, int pageNum, int pageSize, String text) {
        PageHelper.startPage(pageNum, pageSize);
        List<AoaDirector> meShareMess = directorDao.getMeShareMess(userId, text);
        PageInfo<AoaDirector> pageInfo = new PageInfo<>(meShareMess);
        return pageInfo;
    }
    public PageInfo<AoaDirector> getShareMeMess(Long userId, int pageNum, int pageSize, String text) {
        PageHelper.startPage(pageNum, pageSize);
        List<AoaDirector> shareMeMess = directorDao.getShareMeMess(userId, text);
        PageInfo<AoaDirector> pageInfo = new PageInfo<>(shareMeMess);
        return pageInfo;
    }
    public Long addDirector(AoaDirector director) {
        directorDao.addDirector(director);
        return director.getDirectorId();
    }
    public ArrayList<Integer> shareUser(Set<Integer> shareId, int userId, int directorId){

        ArrayList<Integer> msg = new ArrayList<>();
        for (int i :shareId){
            String date = DateUtils.getToday();
            Integer integer = directorDao.checkShare(directorId, i);
            if (integer > 0 ){
                msg.add(i);
            }else{
                directorDao.shareUser(i,userId,directorId,date);
            }
        }
        return msg;
    }

}
